<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
    <div id="box">
        <ul>
            <li v-for="(item,index) in fn" :key="item.id">{{item.name | mimi()}}</li>
        </ul>
    </div>
    <script>
        new Vue({
            el: "#box",
            data: {
                arr: [
                    {
                        name: "张三",
                        age: 15
                    },
                    {
                        name: "李丽丽",
                        age: 18
                    },
                    {
                        name: "斯琴高娃",
                        age: 19
                    },
                    {
                        name: "啊伟",
                        age: 20
                    }
                ],
            },
            // methods: {
            //     fn() {
            //         var a = this.arr.filter(item => item.age > 18)
            //         return a
            //     }
            // },
            computed: {
                fn() {
                    var a = this.arr.filter(item => item.age > 18)
                    return a
                }
            },
            filters: {
                mimi(a) {
                    if (a.length == 2) {
                        return a.substr(0, 1) + "*"
                    } else if (a.length == 3) {
                        return a.substr(0, 1) + "**"
                    } else if (a.length == 4) {
                        return a.substr(0, 1) + "***"
                    }
                }
            }
        })
    </script>
</body>

</html>